'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// 父类点赞按钮
var PraiseButton = function () {
  function PraiseButton() {
    var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'red';

    _classCallCheck(this, PraiseButton);

    // 点赞次数
    this.hasPraise = 0;
    // 点赞文字
    this.btnContent = '点赞';
    // 按钮
    this.praiseBtn = document.createElement("button");
    // 背景颜色
    this.bgColor = color;

    this.render();
  }

  // 更新点赞数字


  _createClass(PraiseButton, [{
    key: 'update',
    value: function update(num) {
      this.praiseBtn.innerHTML = this.btnContent + '      ' + this.hasPraise;
    }

    // 渲染按钮

  }, {
    key: 'render',
    value: function render() {
      var _this = this;

      // const wrapper = document.querySelector(".homeworkWrapper");
      this.praiseBtn.innerHTML = this.btnContent + '      ' + this.hasPraise;
      this.praiseBtn.className = "praise-btn";
      this.praiseBtn.style.backgroundColor = this.bgColor;
      document.body.appendChild(this.praiseBtn);

      this.praiseBtn.addEventListener('click', function () {
        if (_this.hasPraise >= 1) {
          _this.hasPraise = 0;
          _this.btnContent = '点赞';
          _this.update(_this.hasPraise);
        } else {
          _this.hasPraise++;
          _this.btnContent = "取消";
          _this.update(_this.hasPraise);
        }
      });
    }
  }]);

  return PraiseButton;
}();

// 子类Thumb


var Thumb = function (_PraiseButton) {
  _inherits(Thumb, _PraiseButton);

  function Thumb(color) {
    _classCallCheck(this, Thumb);

    // 背景颜色
    var _this2 = _possibleConstructorReturn(this, (Thumb.__proto__ || Object.getPrototypeOf(Thumb)).call(this, color));

    _this2.bgColor = color;
    return _this2;
  }

  return Thumb;
}(PraiseButton);

// new PraiseButton();

var tb = new Thumb('red');
//把这个变量注册到window， 不然测试的时候拿不到这个变量， 在实际开发中可以用 import把代码导到 测试文件里
window.tb = tb;

// new Thumb("orange");
// new Thumb("deeppink");
// new Thumb("purple");
// new Thumb("blue");
"use strict";
